package com.dxf.springcloud.controller;

import com.dxf.springcloud.entities.CommonPayment;
import com.dxf.springcloud.entities.Payment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * 80端口调用8001服务提供者端口
 */
@RestController
@RequestMapping("/consumer")
public class OrderController {

    public static final String PAYMENT_URL="http://localhost:8001";


    @Autowired
    private RestTemplate restTemplate;

    /**
     * 创建
     * @param payment
     * @return
     */
    @GetMapping("/payment/create")
    public CommonPayment create(Payment payment){
        return restTemplate.postForObject(PAYMENT_URL+"/payment/create",payment,CommonPayment.class);
    }


    @GetMapping("/payment/getPaymentById/{id}")
    public CommonPayment<Payment>  getPaymentById( @PathVariable("id") Long id){
        return restTemplate.getForObject(PAYMENT_URL+"/payment/getPaymentById/"+id,CommonPayment.class);
    }


}
